class Solution:
    def rangeBitwiseAnd(self, m: int, n: int) -> 'int':
        bit = lambda x, i: (x // 2**(i)) % 2
        res = 0
        for i in range(n.bit_length()):
            res += 2**i if m // 2**i == n // 2**i and bit(n, i) != 0 else 0
            # print(res)
        return res

if __name__ == '__main__':
    s = Solution()
    print(s.rangeBitwiseAnd(5, 7))
    print(s.rangeBitwiseAnd(2, 2))
    print(s.rangeBitwiseAnd(4, 5))
